window.onload = function() {
	var fm = document.flow;
	var delivery_radio = fm.delivery_radio;
	var pay_radio = fm.pay_radio;
	var delivery = document.getElementById('delivery');
	var pay = document.getElementById('pay');
	var total_all = document.getElementById('total_all');
	var price = document.getElementById('price');
	var sum = 0;
	document.getElementById('price1').innerHTML = '起步费用';
    document.getElementById('price2').innerHTML = '额外费用';
	for(var i=0;i<pay_radio.length;i++) {
        if(pay_radio[i].checked == true) {
            pay.innerHTML = pay_radio[i].value;
            total_all.getElementsByTagName('strong')[2].innerHTML = pay_radio[i].value;
            fm.pay.value = pay_radio[i].title;
        }
    }
    for(var i=0;i<total_all.getElementsByTagName('strong').length;i++) {
    	sum += Number(total_all.getElementsByTagName('strong')[i].innerHTML);
    	price.innerHTML = sum;
    	fm.price.value = sum; 
    }
}

function changeDelivery(obj) {
	var fm = document.flow;
	var delivery = document.getElementById('delivery');
	var sum = 0;
	var total_all = document.getElementById('total_all');
	delivery.innerHTML = obj.value;
	fm.delivery.value = obj.title;
	document.getElementById('price1').innerHTML = obj.value;
	document.getElementById('price2').innerHTML = obj.getAttribute('add');
	var addPrice = (parseFloat(document.getElementById('price3').innerHTML) - 10) < 0 ? 0 : parseFloat(document.getElementById('price3').innerHTML) - 10
	delivery.innerHTML = Math.round((parseFloat(document.getElementById('price1').innerHTML) + (addPrice) * parseFloat(document.getElementById('price2').innerHTML)) * 100) / 100; 
	total_all.getElementsByTagName('strong')[1].innerHTML = delivery.innerHTML;
	for(var i=0;i<total_all.getElementsByTagName('strong').length;i++) {
        sum += Number(total_all.getElementsByTagName('strong')[i].innerHTML);
        price.innerHTML = sum;
        fm.price.value = sum; 
    }
}

function changePay(obj) {
	var fm = document.flow;
    var pay = document.getElementById('pay');
    var sum = 0;
    var total_all = document.getElementById('total_all');
    pay.innerHTML = obj.value;
    fm.pay.value = obj.title;
    total_all.getElementsByTagName('strong')[2].innerHTML = obj.value;
    for(var i=0;i<total_all.getElementsByTagName('strong').length;i++) {
        sum += Number(total_all.getElementsByTagName('strong')[i].innerHTML);
        price.innerHTML = sum;
        fm.price.value = sum; 
    }
}

function checkFlow() {
	var delivery = document.flow.delivery_radio;
	var d_warning = document.getElementById('d_warning');
	for(var i=0;i<delivery.length;i++) {
		if(delivery[i].checked) return true;
	}
    delivery[0].focus();
    d_warning.style.display = 'block';
    return false;
}



